#!/usr/bin/python2
# -*- coding: UTF-8 -*-

import logging
import urllib2
import urllib
import sys
import os
import re
import json
import codecs
import copy
import ConfigParser
from time import time

from house import house_service
from image import image_service
from jobs import jobs_service
from taobao import taobao_service
from tabelog import tabelog_service
from douding import douding_service

def log_conf():
    logging.basicConfig(level=logging.DEBUG,
        format='%(asctime)s %(filename)s+%(lineno)d [%(levelname)s] %(message)s',
        filemode='w')

def main():
    log_conf()

    start_time = time()
    logging.info('startup ndcasp')

    house_process = house_service.HouseService()
    image_process = image_service.ImageService()
    jobs_process = jobs_service.JobsService()
    taobao_process = taobao_service.TaobaoService()
    tabelog_process = tabelog_service.TabelogService()
    douding_process = tabelog_service.DoudingService()

    # read config
    ndcasp_config = ConfigParser.ConfigParser()
    ndcasp_config.read("./config/ndcasp.ini")
    secs = ndcasp_config.sections()
    for sec in secs:
        opts = ndcasp_config.options(sec)
        for opt in opts:
            val = ndcasp_config.get(sec, opt)
            if opt == "hourse" and val == "on":
                house_process.startup()
            elif opt == "image" and val == "on":
                image_process.startup()
            elif opt == "jobs" and val == "on":
                jobs_process.startup()
            elif opt == "taobao" and val == "on":
                taobao_process.startup()
            elif opt == "tabelog" and val == "on":
                tabelog_process.startup()
            elif opt == "douding" and val == "on":
                tabelog_process.startup()

    end_time = time()

    logging.info('use time : %d(s)' % (end_time - start_time))
    logging.info('end ndcasp')

if __name__ == '__main__':
    main()
else:
    pass